<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户管理</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
	var $dg;
	$(function() {
		$dg = $("#dg").datagrid({
			url: base.contextPath+"/sysmgr/user/datagrid.do",
			title: '<span style="font-weight:normal;color:#666;">系统基础配置-->机构用户-->用户管理</span>', 
			idField: 'id', fit: true, border: false, pageSize: 30, pageList: [30,40,50,100,200], rownumbers: true,
			remoteSort: false, toolbar: '#toolbars', striped:true, pagination: true, singleSelect: false,
			frozenColumns: [[
			    { field: 'ck', checkbox: true },
			    { field: 'id', title: 'ID', width: 80, hidden: true },
			    { field: 'num', title: '编号', width: 80, sortable: true }
			]],
			columns: [[
			    { field: 'company_name', title: '公司', width: 150, tooltip: true },
			    { field: 'dept_name', title: '部门', width: 100 },
			    { field: 'workgroup_names', title: '工作组', width: 100, tooltip: true },
			    { field: 'userrole_names', title: '所属角色', width: 100, tooltip: true },
			    { field: 'permits_names', title: '权限组', width: 100, tooltip: true },
			    { field: 'truename', title: '姓名', width: 100, sortable: true },
			    { field: 'account', title: '登录账号', width: 100, sortable: true }, 
			    { field: 'password', title: '&nbsp;登录密码', width: 80, sortable: true, align: 'center'},
			    { field: 'status', title: '&nbsp;账号状态', width: 80, sortable: true, align: 'center', formatter:function(value,row){
			    	if(value == 0){return "<font color='green'>正常</font>";}else if(value == 1){return "<font color='red'>锁定</font>";}
			    }},
			    { field: 'sex', title: '性别', width:50, sortable: true, align: 'center'},
			    { field: 'mobile', title: '手机号码', width:100, sortable: true },
			    { field: 'email', title: '邮箱地址', width: 200, formatter: function(value, row) {
			    	return $.string.format("<a href='javascript:alert(\"打开邮件发送窗口{0}\");' class='clickLInk ext_email'>{1}</a>", "send", value) ;
			    } },
			    { field: 'lastAcceccTime', title: '最后访问', width: 140, sortable: true },
			    { field: 'diffDatetime', title: '离线', width: 180, sortable: true },
			    { field: 'created', title: '创建时间', width: 140, sortable: true },
			    { field: 'modifyDate', title: '最后修改时间', width: 140, sortable: true },
			    { field: 'modifyName', title: '修改者', width: 80, sortable: true }
			]],
			onLoadSuccess: function(node, data) {
				$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
				$dg.datagrid('unselectAll');
			}
		}) ;
		company_search = $("#company_search").combotree(); dept_search = $("#dept_search").combotree();
		company_search.combotree({
			url : base.contextPath+"/sysmgr/company/doNotNeedAuth_tree.do",
			editable: false, lines:true,
			onChange: function(newValue, oldValue) {
				$dg.datagrid("load",{company_id: newValue});
				dept_search.combotree({
        			url : base.contextPath+"/sysmgr/dept/doNotNeedAuth_tree.do?company_id="+newValue,
        			editable: false, lines:true,
        			onChange: function(newValue, oldValue) {
        				$dg.datagrid("load",{dept_id: newValue});
        			}
        	    });
            }
	    });
	});
	
	function doSearch(value,name){
		var o = {} ; o[name] = value ; $dg.datagrid("load",o);
	}
	function searchBox() {
		var search_form = $("#searchForm").form("getData") ; 
		$dg.datagrid("load",search_form);
	}
	function searchGroup() {
		var search_form = parent.$("#form").form("getData") ; 
		$dg.datagrid("load",search_form);
	}
	
	function search_dialog() {
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/doNotNeedAuth_search.do", title: "搜索", iniframe: false, topMost: true,
			width: 400, height: 550,modal: false, collapsible: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '搜索', iconCls : 'ext_save', handler : function() { searchGroup(); } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function form_edit(form) {
		var form_url = base.contextPath+"/sysmgr/user/user_form.do" ;
		if("E" == form) {
			var node = $dg.datagrid('getSelected');
			if (node) {
				form_url = base.contextPath+"/sysmgr/user/user_form.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true,
			width: 900, height: 400, maximizable: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存并继续', iconCls : 'icon-standard-disk', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return false;
		}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				$.post(base.contextPath+"/sysmgr/user/delete.do", {"ids" : ids.join(',')}, function(result) {
					if (result.status) {
						$dg.datagrid('unselectAll');$dg.datagrid('reload') ;
						alertify.success(result.msg);
						$.easyui.loaded();
					} else {
						alertify.success(result.msg);
						$.easyui.loaded();
					}
				}, 'json').error(function() { $.easyui.loaded(); });
			}
		});
	}
	
	
	function batch_dept() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/user_dept_page.do?ids="+ids.join(','), 
			title: "批量调换部门", iniframe: false, topMost: true, width: 400, height: 330,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function batch_workgroup() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/user_group_page.do?ids="+ids.join(','), 
			title: "批量添加工作组", iniframe: false, topMost: true, width: 600, height: 530,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function batch_userrole() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/user_role_page.do?ids="+ids.join(','), 
			title: "批量添加角色", iniframe: false, topMost: true, width: 600, height: 530,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function batch_permits() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/user_permits_page.do?ids="+ids.join(','), 
			title: "批量添加权限去", iniframe: false, topMost: true, width: 600, height: 530,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function lockAccount() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/user_lockAccount_page.do?ids="+ids.join(','), 
			title: "锁定账号", iniframe: false, topMost: true, width: 340, height: 147,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function clearPwd() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据添加中，请稍等..."});
				$.post(base.contextPath+"/sysmgr/user/clearPwd.do", {ids: ids.join(',')}, function(result) {
					if (result.status) {
						$dg.datagrid("reload");
						alertify.success(result.msg);$.easyui.loaded();
					} else {
						$.easyui.loaded();warning.success(result.msg);
					}
				}, 'json').error(function() { $.easyui.loaded(); });
			}
		});
	}
	
	function resetPwd() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		var $d = $.easyui.showDialog({
			href: base.contextPath+"/sysmgr/user/user_resetPwd_page.do?ids="+ids.join(','), 
			title: "重设密码", iniframe: false, topMost: true, width: 340, height: 147,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function notifyNullPwd() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				ids.push(rows[i].id);
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		alert("提醒空密码用户，修改密码！");
	}
	
</script>
</head>

<body>

	<div id="dg">
		<div id="toolbars">
            <a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
            <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
            <a onClick="del();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
            <a onclick="$dg.datagrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
            <a onClick="$dg.datagrid('unselectAll');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-application-xp'">取消选中</a>
            <input class="easyui-searchbox" data-options="searcher:doSearch,width: 250, height: 26, prompt: '请输入关键词', menu: '#topSearchboxMenu'" />
			<div id="topSearchboxMenu" style="width: 85px;">
				<div data-options="name:'num', iconCls: 'icon-hamburg-zoom'">编号查询</div>
				<div data-options="name:'account', iconCls: 'icon-hamburg-zoom'">登录账号</div>
				<div data-options="name:'truename', iconCls: 'icon-hamburg-zoom'">真实姓名</div>
				<div data-options="name:'email', iconCls: 'icon-hamburg-zoom'">邮件地址</div>
			</div>
            <a onClick="$dg.datagrid('load',{});" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-zoom-out'">重置过滤</a>
            <div id="search_bar">
            	<div class="sbox">
            		<div class="sinput">
            			<form id="searchForm">
	            			公司：<input id="company_search" name="company_id" style="width:180px;" />
	            			部门：<input id="dept_search" name="dept_id" style="width:180px;" />
	            			日期查询：<input name="startDate" style="width:100px;" class="easyui-my97" type="text" readonly="readonly" data-options="isShowClear:false, maxDate:new Date()" />
	            			至<input name="endDate" style="width:100px;" class="easyui-my97" type="text" readonly="readonly" data-options="isShowClear:false, maxDate:new Date()" />
            			</form>
            		</div>
            		<div class="sbto">
            			<a href="javascript:searchBox();" class="botbox">查询</a>
		        		<a href="javascript:search_dialog();" class="botbox">复杂查询</a>
            		</div>
            	</div>
            	<div class="sbox">
            		<div class="sbto">
		        		<a href="javascript:lockAccount();" class="botbox">锁定账号</a>
            			<a href="javascript:clearPwd();" class="botbox">清空密码</a>
		        		<a href="javascript:resetPwd();" class="botbox">重设密码</a>
		        		<a href="javascript:notifyNullPwd();" class="botbox">提醒空密码用户</a>
		        		<a href="javascript:batch_workgroup();" class="botbox">批量添加工作组</a>
		        		<a href="javascript:batch_userrole();" class="botbox">批量添加角色</a>
		        		<a href="javascript:batch_permits();" class="botbox">批量添加权限组</a>
		        		<a href="javascript:batch_dept();" class="botbox">批量调换部门</a>
            		</div>
            	</div>
            </div>
        </div>
	</div>
	

</body>
</html>